package com.ruoyi.staffDuty.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.staffDuty.domain.bo.MtStaffDutyFileBo;
import com.ruoyi.staffDuty.domain.vo.MtStaffDutyFileVo;
import com.ruoyi.staffDuty.service.IMtStaffDutyFileService;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 员工类型文件
 *
 * @author ruoyi
 * @date 2023-11-06
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/staff/staffDuty")
public class MtStaffDutyFileController extends BaseController {

    private final IMtStaffDutyFileService iMtStaffDutyFileService;

    /**
     * 查询员工类型文件列表
     */
    //@SaCheckPermission("staff:staffDuty:list")
    @GetMapping("/list")
    public TableDataInfo<MtStaffDutyFileVo> list(MtStaffDutyFileBo bo, PageQuery pageQuery) {
        return iMtStaffDutyFileService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工类型文件列表
     */
    //@SaCheckPermission("staff:staffDuty:export")
    @Log(title = "员工类型文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MtStaffDutyFileBo bo, HttpServletResponse response) {
        List<MtStaffDutyFileVo> list = iMtStaffDutyFileService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工类型文件", MtStaffDutyFileVo.class, response);
    }

    /**
     * 获取员工类型文件详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("staff:staffDuty:query")
    @GetMapping("/{id}")
    public R<MtStaffDutyFileVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iMtStaffDutyFileService.queryById(id));
    }

    /**
     * 新增员工类型文件
     */
    //@SaCheckPermission("staff:staffDuty:add")
    @Log(title = "员工类型文件", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MtStaffDutyFileBo bo) {
        return toAjax(iMtStaffDutyFileService.insertByBo(bo));
    }

    /**
     * 修改员工类型文件
     */
    //@SaCheckPermission("staff:staffDuty:edit")
    @Log(title = "员工类型文件", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MtStaffDutyFileBo bo) {
        return toAjax(iMtStaffDutyFileService.updateByBo(bo));
    }

    /**
     * 删除员工类型文件
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("staff:staffDuty:remove")
    @Log(title = "员工类型文件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iMtStaffDutyFileService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
